﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Web.Mvc;
using System.Web.Security;
using System.Web.UI.WebControls;
using System.Collections;
using System.Linq;

namespace ElectronicDiary.Models.Teacher
{
    public class SubjectClassSelectModel
    {
        [Required(ErrorMessage = "{0} jest wymagana.")]
        [Display(Name = "Klasa")]
        public int IDClass { get; set; }

        [Required(ErrorMessage = "{0} jest wymagana.")]
        [Display(Name = "Klasa")]
        public int IDSubject { get; set; }

        public IEnumerable<SelectListItem> Classes
        {
            get
            {
                using (var context = new electronicDiaryEntities())
                {
                    var collection = context.@class.ToDictionary(n => n.idClass, n => n.Name);
                    IEnumerable<SelectListItem> sli;
                    sli = collection.Select(n => new SelectListItem
                    {
                        Value = n.Key.ToString(),
                        Text = n.Value
                    }).OrderBy(n => n.Text);
                    return sli;
                }
            }
        }

        public IEnumerable<SelectListItem> Subjects
        {
            get
            {
                using (var context = new electronicDiaryEntities())
                {
                    var collection = context.subject.ToDictionary(n => n.idSubject, n => n.name);
                    IEnumerable<SelectListItem> sli;
                    sli = collection.Select(n => new SelectListItem
                    {
                        Value = n.Key.ToString(),
                        Text = n.Value
                    }).OrderBy(n => n.Text);
                    return sli;
                }
            }
        }
    }
}